package com.vcredit.bird.service.report;

import java.util.Map;

import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.vcredit.bird.service.base.BirdService;
import com.vcredit.framework.annotation.Log;
import com.vcredit.framework.util.HttpRequest;
import com.vcredit.framework.util.JacksonUtil;

/**
 * 客户资质 报表 ------征信账单拉取
 * 
 * @author chengxin
 *
 */
@Service
public class CustomerQualificationService extends BirdService {
	@Value("${credit.check.url}")
	private String creditUrl;

	@Value("${mobile.bill.query}")
	private String MOBILE_BILL_CRAWLER;

	private static Logger logger = LoggerFactory.getLogger(CustomerQualificationService.class);

	public String reportPull(Object obj) throws Exception {
		String resultJson = "";
		try {
			String json = JacksonUtil.Obj2Json(obj);
			logger.info("征信账单请求Json" + resultJson);
			resultJson = HttpRequest.doJson(creditUrl, json);
			logger.info("征信账单详情" + resultJson);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			logger.error("拉取征信详单失败！", e.getMessage());
		}
		return resultJson;
	}

	@Log
	public Object pullbill(Object obj) throws Exception {
		// TODO Auto-generated method stub

		String jsonResult = reportPull(obj);
		return jsonResult;
	}

	public Object mobileBill(Object obj) {
		String resultJson = "";
		try {
			String json = JacksonUtil.Obj2Json(obj);
			logger.info("手机账单请求Json" + json+"---url=="+MOBILE_BILL_CRAWLER);
			
			resultJson = HttpRequest.doJson(MOBILE_BILL_CRAWLER, Base64.encodeBase64String(json.getBytes("utf-8")));
			logger.info("手机账单拉取详情" + resultJson);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			logger.error("手机账单拉取失败！", e.getMessage());
		}
		return resultJson;
	}
}
